/*
 * $Id: Globals.h 417 2011-01-21 07:33:19Z chunghh $
 */

#ifndef _GLOBALS_H_
#define _GLOBALS_H_

#include <xp/types.h>
#include <xp/macros.h>
#include <xp/bas/sysapi.h>
#include <xp/utl/log.h>
#include <xp/Exception.hpp>
#include <xp/bas/Mutex.hpp>
#include <xp/sys/Path.hpp>
#include <xp/net/UdpSocket.hpp>
#include "AppEnv.h"
#include "MainApp.h"

using namespace xp;
using namespace xp::bas;
using namespace xp::sys;
using namespace xp::utl;

#define APP_MODE_BACKGROUND 0
#define APP_MODE_FOREGROUND 1

extern int          app_mode;
extern xp_log_t     app_log;
extern MainApp*     app_main;
extern Path         app_path;
extern xp_mchar_t   app_mdir[XP_PATH_MAX + 1];

#define APP_NAME                      XP_T("xpkit-daemon")
#define APP_VERSION                   XP_T("1.0.0")
#define APP_INI_FILE                  XP_T("xpkit-daemon.ini")
#define APP_LOG_FILE                  XP_T("xpkit-daemon.log")
#define APP_FILE_PERM                 0600

#ifndef APP_CFG_DIR
#	define APP_CFG_DIR app_path.baseDir()
#endif

#ifndef APP_LOG_DIR
#	define APP_LOG_DIR app_path.baseDir()
#endif

#define APP_YES                       XP_T("yes")
#define APP_NO                        XP_T("no")
#define APP_GATE_TCP_SERVICE          XP_QUOTE(1001)
#define APP_GATE_MAX_CONNECTIONS_MIN  0  // 0 means unlimited, however
#define APP_GATE_MAX_CONNECTIONS_MAX  100
#define APP_GATE_MAX_CONNECTIONS      30
#define APP_GATE_TIMEOUT_MIN          -1  // -1: unlimited
#define APP_GATE_TIMEOUT_MAX          3600000
#define APP_GATE_TIMEOUT              -1

#define APP_LOGGING_TARGET_FILE       XP_T("file")
#define APP_LOGGING_TARGET_SYSLOG     XP_T("syslog")
#define APP_LOGGING_TARGET_CONSOLE    XP_T("console")

#define APP_ENV_LOGGING_TARGET        XP_T("MAIN*LOGGING_TARGET")
#define APP_ENV_LOGGING_LEVEL         XP_T("MAIN*LOGGING_LEVEL")

#define APP_ENV_GATE_ENABLE_TCP       XP_T("GATE*ENABLE_TCP")
#define APP_ENV_GATE_TCP_SERVICE      XP_T("GATE*TCP_SERVICE")
#define APP_ENV_GATE_TCP_LOCAL_ONLY   XP_T("GATE*TCP_LOCAL_ONLY")
#define APP_ENV_GATE_MAX_CONNECTIONS  XP_T("GATE*MAX_CONNECTIONS")
#define APP_ENV_GATE_TIMEOUT          XP_T("GATE*TIMEOUT")

#endif
